<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 15-6-23
 * Time: 上午10:01
 * @author 郑钟良<zzl@ourstu.com>
 */

namespace Addons\Consult\Model;


use Think\Model;

class ConsultModel extends Model{

    public function getList($map,$order='create_time desc',$limit=20,$page=1)
    {
        $totalCount=$this->where($map)->count();
        if($totalCount){
            $list=$this->where($map)->order('create_time desc')->page($page,$limit)->select();
            foreach($list as &$val){
                $val['user_nickname']=get_nickname($val['uid']);
            }
            unset($val);
        }
        return array($list,$totalCount);
    }

    public function getData($id)
    {
        $data=$this->find($id);
        return $data;
    }

    public function editData($data)
    {
        if($data['id']){
            if(mb_strlen($data['answer'],'utf-8')>0){
                $info=$this->getData($data['id']);
                if(!$info['answer_uid']){
                    $data['answer_uid']=get_uid();
                }
            }
            $res=$this->save($data);
        }else{
            $res=$this->add($data);
        }
        return $res;
    }

} 